package com.freddy.sqlite.main.controller;

import android.app.Activity;
import android.os.Bundle;

import com.freddy.sqlite.FreddyChenApplication;
import com.freddy.sqlite.R;
import com.freddy.sqlite.db.UserDB;
import com.freddy.sqlite.main.model.User;

import java.util.List;

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
//        if(!UserDB.getInstance(FreddyChenApplication.getInstance()).hasData()) {
        new Thread(new Runnable() {

            @Override
            public void run() {
                int count = 3;
                long timeOne = System.currentTimeMillis();
                for(int i = 0; i < count; i++) {
                    UserDB.getInstance(FreddyChenApplication.getInstance()).insertTestData();
                }
                long timeTwo = System.currentTimeMillis();
                System.out.println("插入" + count + "条数据耗时：" + (timeTwo - timeOne) + "ms");

                List<User> userList = UserDB.getInstance(FreddyChenApplication.getInstance()).queryAll();
                long timeThree = System.currentTimeMillis();
                System.out.println("查询" + userList.size() + "条数据耗时：" + (timeThree - timeTwo) + "ms");

                for(User user : userList) {
                    System.out.println("userInfo：");
                    System.out.println("----------------------------------");
                    System.out.println(user);
                    System.out.println("**********************************");
                }
            }
        }).start();
//        }
    }
}
